{% load staticfiles %}
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <link rel="stylesheet" type="text/css"
          href="{% static 'h-ui/css/H-ui.min.css' %}" />
    <link rel="stylesheet" type="text/css"
          href="{% static 'h-ui.admin/css/H-ui.admin.css' %}" />
    <link rel="stylesheet" type="text/css"
          href="{% static 'lib/Hui-iconfont/1.0.8/iconfont.css' %}" />
    <link rel="stylesheet" type="text/css"
          href="{% static 'h-ui.admin/skin/default/skin.css' %}" id="skin" />
    <link rel="stylesheet" type="text/css"
          href="{% static 'h-ui.admin/css/style.css' %}" />
    <link rel="stylesheet" type="text/css"
          href="{% static 'lib/select2/css/select2.min.css' %}" />
    <script type="text/javascript"
            src="{% static 'lib/jquery/1.9.1/jquery.min.js'%}"></script>
    <script type="text/javascript"
            src="{% static 'lib/layer/2.4/layer.js'%}"></script>
    <script type="text/javascript"
            src="{% static 'h-ui/js/H-ui.js'%}"></script>
    <script type="text/javascript"
            src="{% static 'lib/select2/js/select2.full.min.js'%}"></script>
</head>
<body>
<div class="Huialert Huialert-info">请选择需要授权用户，然后保存。</div>
<br/>
<form method="post" action="" id="userForm">
    <select class="select-multiple-user" name="selectUser" multiple="multiple" style="width:100%;",>
        {%for user in users%}
            <option value="{{user.id}}" selected>{{user}}</option>
        {%endfor%}
        {%for guest in guests%}
            <option value="{{guest.id}}">{{guest}}</option>
        {%endfor%}
    </select>
    <input name="app_id" value="{{app_id}}" hidden/>
    <input name="action_id" value="{{action_id}}" hidden/>
    <input name="env_id" value="{{env_id}}" hidden/>
    <br/>
    <br/>
    <br/>
    <div class="r">
        <button class="btn btn-danger radius" id="saveBtn" type="button">保存修改</button>
    </div>
</form>
<script>
$(document).ready(function() {
    $('.select-multiple-user').select2({
        placeholder: "点击鼠标，可下拉选择，也可输入再选择",
        allowClear: true
    });

    $("#saveBtn").click(function(e){
        e.preventDefault();
        var group_data = $("#userForm").serialize();
        console.log(group_data);
        $.ajax({
            type: "POST",
            data:{
                group_data: group_data,
            },
            url: "{% url 'rightadmin:update_permission' %}",
            dataType : "json",
            success: function(data) {
                console.log(data);
                if (data['return'] == 'error') {
                    $.Huimodalalert("<span class='c-danger'>亲，没有权限更新哟~</span>",3000);
                }
                if (data['return'] == 'success') {
                    $.Huimodalalert("<span class='c-success'>权限更改成功！</span>",3000);
                }
            },
            error : function(){
                $.Huimodalalert("<span class='c-danger'>系统出现问题</span>",3000);
            }
        });
    });
});
</script>
</body>
</html>